# -------------------------------------------------------------------
# This is the default mkgmap style file for applying rules on
# OSM relations.  Usually you will set tags on the
# elements that make up the relation, and the tags will be
# processed by the rules defined in the "points" or "lines" files.
#
# Any line prefaced with # is a comment and will not be applied.
# Each line is a rule, of the generalised format:
#  OSM_tag(s)_to_match  [Garmin_type_code resolution]
# See http://wiki.openstreetmap.org/wiki/Mkgmap/help/style_rules
# and http://wiki.openstreetmap.org/wiki/Mkgmap/help/Custom_styles
# for more information.

# Names of administrative boundaries.
# We could want to sort the relations in ascending order of admin_level
# and alphabetically by name first.
# Currently, the matching relations will be processed and the names
# appended to the boundary lines in an arbitrary order.

type=multipolygon
{ apply role=inner
  {
    set roletag=inner
  }
}

type=multipolygon
{ apply role=outer
  {
    set roletag=outer
  }
}

boundary=administrative {
	apply {
		set member=yes;
	}
}

(type=boundary | type=multipolygon) & boundary=administrative & admin_level=2
{ apply
  {
    set boundary2_name='$(boundary2_name)/${name}' | '${name}';
	set boundary2=yes;
  }
}

border_type = territorial & (admin_level=2 | admin_level=3)
{ apply
  {
    set boundary3_name='$(boundary3_name)/${name}' | '${name}';
	set boundary3=yes;
  }
}

(type=boundary | type=multipolygon) & boundary=administrative & name=* & admin_level=4
{ apply
  {
    set boundary4_name='$(boundary4_name)/${name}' | '${name}';
	set boundary4=yes;
  }
}

(type=boundary | type=multipolygon) & boundary=administrative & name=* & admin_level=8
{ apply
  {
    set boundary8_name='$(boundary8_name)/${name}' | '${name}';
	set boundary8=yes;
	  }
}


type=multipolygon & landuse=forest
	{
		apply {
		set forest_from_relation=yes;
		set fname='${name}';
	}
	}  
	



# map the cycle routes to the lcn, rcn and ncn tags
type=route & name ~ '(Euro Route|EuroVelo|Euro Velo).*' {set network=icn}
type=route & name ~ '(Euro Route R1).*' {set name="Euro Route R1"}
type=route & name ~ '(EuroVelo 1 - part).*' {set name="Atlantic Coast Route"}
type=route & name ~ '(EuroVelo 2).*' {set name="Capitals Route"}
type=route & name ~ '(EuroVelo 3).*' {set name="Pilgrims Route"}
type=route & name ~ '(EuroVelo 4).*' {set name="Central Europe Route"}
type=route & name ~ '(EuroVelo 5).*' {set name="Via Romea Francigena"}
type=route & name ~ '(EuroVelo 6).*' {set name="Atlantic-Black Sea"}
type=route & name ~ '(EuroVelo 7).*' {set name="Central Europe Route"}
type=route & name ~ '(EuroVelo 8).*' {set name="Mediterranean Route"}
type=route & name ~ '(EuroVelo 9).*' {set name="Baltic-Adriatic"}
type=route & name ~ '(EuroVelo 10).*' {set name="Baltic Sea Route"}
type=route & name ~ '(EuroVelo 11).*' {set name="East Europe Route"}
type=route & name ~ '(EuroVelo 12).*' {set name="North Sea Cycle Route"}
type=route & name ~ '(EuroVelo 13).*' {set name="Iron Curtain Trail"}
type=route & name ~ '(EuroVelo 15).*' {set name="Rhine Route"}

route=bicycle & ref="LF-K"
	{
		apply {
		set icn_from_relation=yes;
		set iname="Noordzeefietsroute";
		set iref="EV12";
	} 
	}

route=bicycle & ref="LF-M"
	{
		apply {
		set icn_from_relation=yes;
		set iname="Maasfietsroute";
		set iref="EV19";
	} 
	}

route=bicycle & ref="Rijn"
	{
		apply {
		set icn_from_relation=yes;
		set iname="Rijnfietsroute";
		set iref="EV15";
	} 
	}
	
	route=bicycle & ref="LF13"
	{
		apply {
		set icn_from_relation=yes;
		set iname="Centraal Europe Route";
		set iref="EV4";
	} 
	}
route=bicycle & ref="LF4" & name!="Midden-Nederlandroute - 08 - Borculo - Enschede"
	{
		apply {
		set icn_from_relation=yes;
		set iname="Hoofdstedenroute";
		set iref="EV2";
	} 
	}

route=bicycle & ref="R1;D3"
	{
		apply {
		set icn_from_relation=yes;
		set iname="Hauptstadt-Route";
		set iref="EV2";
	} 
	}	
network=icn
	{
		apply { 
		set icn_from_relation=yes;
		set iname='${iname}/${name}'| '${name}';
		set iref='${iref}/${ref}'| '${ref}';
	} 
	}

type=route & route=bicycle & network=ncn
	{
		apply { 
		set ncn_from_relation=yes;
		set nname='${name}';
		set nref='$(nref)/${ref}' | '${ref}';
	} 
	}	

type=route & route=bicycle & network=rcn & note ~ '[^a-zA-Z].*'
	{
		apply { 
		set rcn_from_relation=yes;
		set rnote='${note}';
		set rref='${note}';
	} 
	}	
	
type=route & route=bicycle & network=rcn
	{
		apply { 
		set rcn_from_relation=yes;
		set rname='${name}';
		set rref='$(rref)/${ref}' | '${ref}';
	} 
	}
	
type=route & route=bicycle & network=rcn & network:type!=node_network
	{
		apply { 
		set rcn_ref='$(rcn_ref)/${ref}' | '${ref}';
	} 
	}
	
type=route & route=bicycle & network=lcn
	{
		apply { 
		set lcn_from_relation=yes;
		set lname='${name}';
		set lref='$(lref)/${ref}' | '${ref}';
	}
	} 	


type=route & route=bicycle & network=tcn
	{
		apply { set tcn_from_relation=yes;
		set tname='${name}';
	}
	} 	
	
network=icn & state=proposed
	{apply { set icn_from_relation=no }}
network=ncn & state=proposed
	{apply { set ncn_from_relation=no }}	
network=rcn & state=proposed
	{apply { set rcn_from_relation=no }}	
network=lcn & state=proposed
	{apply { set lcn_from_relation=no }}
			

	
type=route & route=mtb
	{
		apply {
		set mtb_from_relation=yes;
		set mname='${name}';
	}
	} 
	
type=route & (route=foot | route=hiking)
	{
		apply {
		set hiking_from_relation=yes;
		}
	} 	
	
#train routes
type=route & route=train
	{
		apply { 
		set trainroute=yes;
	} 
	}
	
type=associatedStreet { apply role=house { add addr:street='${name}' }}

	
# Public transportation routes.
# We could want to sort the matching relations by ref first.
type=route
& (route=bus|route=tram|route=light_rail) & ref ~ '([tT]ram|[Bb]us)'
	{
		apply { 
		set refroute=no;
	} 
	}
	
type=route
& (route=bus|route=trolleybus|route=light_rail|route=ferry|route=subway|route=tram)
& (ref=* | name=*)
{
  add ref='${name}'; # if ref is missing, use name
  # Append the ref of the route relation to the route_ref attribute of
  # the member nodes recursively (even to members of subrelations).
  # Stops can be grouped within subrelations comprising the vehicle
  # stop node and the passenger wait node.
  apply { # node role ~ '(start_|end_)stop'
    set routerel_ref='$(routerel_ref|not-equal:ref),${ref}' | '${ref}';
	add refroute='${refroute}/${route|not-equal:refroute}' | '${route}';

    # In route relations, stops may be defined as relations that group
    # the passenger wait area and the vehicle stop area.  If such
    # subrelations exist, copy the ref to them too.
    set mkgmap:ref='${ref}';

    apply role=passengers {
      add routerel_ref='$(routerel_ref),${mkgmap:ref}' | '${mkgmap:ref}';
    }

    delete mkgmap:ref;
  }
  # We could want to copy the route relation name to unnamed route=ferry ways.
  # apply way { add name='${name}' }
}

# remove restrictions for motorcar
type=restriction:motorcar  {delete 'type=restriction:motorcar'}
type=restriction & restriction:motorcar=* {delete restriction:motorcar}

#apply bicycle restrictions also for "motorcar"
type=restriction & restriction:bicycle=* {set restriction:motorcar='${restriction:bicycle}'}
type=restriction:bicycle {set type=restriction}
type=restriction & except ~ '.*bicycle'  {set except='${except};motorcar'}

